package cool.qingqing.lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author 高山青
 * @Date 2022/1/2  -   15:50
 */
public class LomdaDemo02 {
	public static void main(String[] args) {
		List<Person> list=new ArrayList<>();
		list.add(new Person(21,"luck"));
		list.add(new Person(19,"jack"));
		list.add(new Person(25,"mali"));
		Collections.sort(list, new Comparator<Person>() {
			@Override
			public int compare(Person o1, Person o2) {
				return o1.getAge()- o2.getAge();
			}
		});
		list.forEach(System.out::println);
		//lamda表达式的情况
		Collections.sort(list,(Person p1,Person p2)->{
			return p1.getName().compareTo(p2.getName());
		});
		System.out.println("使用lamda表达式的时候");
		list.forEach(System.out::println);

	}

}
class Person{
	private int age;
	private String name;

	public Person(int age, String name) {
		this.age = age;
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Person() {
	}

	@Override
	public String toString() {
		return "Person{" +
				"age=" + age +
				", name='" + name + '\'' +
				'}';
	}


}